package com.block.source.service;


import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.block.common.model.vo.ResultInfoVO;
import com.block.common.service.LogFactory;
import com.block.db.entity.SourceBaseInfo;
import com.block.source.model.dto.SourceApiParam;
import com.block.source.model.dto.SourceApiResult;
import com.block.source.model.param.UserDataParam;
import org.slf4j.Logger;

import java.util.Map;

public abstract class  ISourceReceiveService {

    private static final Logger log = LogFactory.getSourceLog();

    public abstract SourceApiResult handleCheckUserData(SourceBaseInfo sourceBaseInfo, Map<String, String[]> parameterMap, String paramContent);

    public abstract SourceApiResult handleRegisterUserData(SourceBaseInfo sourceBaseInfo, Map<String, String[]> parameterMap, String paramContent);

    public abstract SourceApiResult getCheckUserReturnData(SourceBaseInfo sourceBaseInfo, ResultInfoVO resultInfoVO, SourceApiParam sourceApiParam);

    public abstract SourceApiResult getRegisterUserReturnData(SourceBaseInfo sourceBaseInfo, ResultInfoVO resultInfoVO,SourceApiParam sourceApiParam);

    public abstract JSONObject getError(String message);

    public abstract JSONObject getSuccess();

    public abstract UserDataParam getUserDataParam(String paramContent);


    // 撞库参数校验
    public static String verifyCheckUserParam(UserDataParam userDataParam){

        if (StrUtil.isEmpty(userDataParam.getCityCode())){
            return "城市信息为空/不支持；city:" + userDataParam.getCity();
        }

        Integer age = userDataParam.getAge();
        if (age < 23 || age > 55){
            return "年龄范围需要在23-55";
        }

        if (StrUtil.isEmpty(userDataParam.getMobileMd5())){
            return "手机号md5值为空";
        }

        if (StrUtil.isEmpty(userDataParam.getUserIp())){
            return "用户ip为空";
        }

        // 判断资质信息是否有空值
        if (ObjectUtil.hasEmpty(
                userDataParam.getLoanAmount(), userDataParam.getLoanTime(), userDataParam.getHouse(), userDataParam.getCar(), userDataParam.getGjj()
                , userDataParam.getShebao(), userDataParam.getBaoxian(), userDataParam.getZhima(), userDataParam.getHuabei(), userDataParam.getBaitiao()
                , userDataParam.getWeili(), userDataParam.getShouru(), userDataParam.getXueli(), userDataParam.getYongtu(), userDataParam.getYuqi()
                , userDataParam.getXinyongka(), userDataParam.getGongzuo()
        )){
            log.info("【资质信息】【loanAmount】{}【loanTime】{}【house】{}【car】{}【gjj】{}【shebao】{}" +
                    "【baoxian】{}【zhima】{}【huabei】{}【baitiao】{}【weili】{}【shouru】{}【xueli】{}" +
                    "【yongtu】{}【yuqi】{}【xinyongka】{}【gongzuo】{}",
                    userDataParam.getLoanAmount(), userDataParam.getLoanTime(), userDataParam.getHouse(), userDataParam.getCar(), userDataParam.getGjj()
                    , userDataParam.getShebao(), userDataParam.getBaoxian(), userDataParam.getZhima(), userDataParam.getHuabei(), userDataParam.getBaitiao()
                    , userDataParam.getWeili(), userDataParam.getShouru(), userDataParam.getXueli(), userDataParam.getYongtu(), userDataParam.getYuqi()
                    , userDataParam.getXinyongka(), userDataParam.getGongzuo()
            );
            return "资质信息有空值";
        }

        return null;
    }


}
